package com.hundsun.fmbp.deploy.exception;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

import com.hundsun.fmbp.deploy.bean.MsgBean;
import com.hundsun.fmbp.deploy.constants.ReturnCode;

/**
 * 全局异常处理
 * 
 * @ClassName: GlobalExceptionHandler
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author chenc
 * @date 2017年6月22日 下午5:46:37
 *
 */
@ControllerAdvice
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
    private Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public MsgBean jsonHandler(Exception e) {
        logger.error(e.getMessage(), e);
        return new MsgBean(ReturnCode.FAILURE, e.getMessage());
    }
}
